Event Triggers
Event triggers allow BindAI automation logic to react when an event is published through anEventBus.
The current implementation provides a lightweight EventTrigger abstraction. An EventTrigger subscribes to one named event and calls a target function whenever that event is published.
This makes event-driven automation possible without coupling the trigger to a specific agent, workflow, or application object.
For background execution, an event-trigger target can invoke an AutomationWorker. Event triggering and background execution remain separate responsibilities.
EventTrigger
The implementation is located at:EventTrigger extends the base Trigger class and requires three values:
- an
EventBus - an event name
- a callable target
Event object.
Trigger Lifecycle
Every trigger inherits from the baseTrigger abstraction.
The base class provides:
EventTrigger implements these lifecycle operations by subscribing and unsubscribing from its configured EventBus.
Attaching
Calling:attach() more than once does not create duplicate subscriptions. The implementation tracks whether the trigger is already attached.
Detaching
Calling:detach() when the trigger is already detached is safe.
Enabling and Disabling
Triggers are enabled by default. A trigger can be temporarily disabled:Event Bus
EventTrigger does not create its own event system.
Instead, it receives an existing EventBus:
ExecutionContext:
EventBus interface. It does not need to know which component created the event bus.
Event Names
EventTrigger subscribes to the event name supplied when it is created:
EventBus.
Use event names that correspond to events actually published by the application.
BindAI currently publishes structured events for areas including:
- application lifecycle
- agent execution
- workflow execution
- workflow nodes
- human tasks
- model requests and responses
- tool execution
- memory operations
- MCP connection lifecycle
Event Objects
The target receives the completeEvent instance:
Example with an Execution Context
A simple event-driven setup can use the event bus owned by anExecutionContext:
context.events, the trigger calls handle_agent_event.
When the trigger is no longer required:
Trigger Targets
The target must be a callable that accepts anEvent:
EventTrigger implementation does not impose a special target interface beyond the callable receiving an Event.
Multiple Triggers
Multiple triggers can subscribe to the same event bus. For example:Multiple Triggers for One Event
Multiple triggers can also subscribe to the same event:EventBus dispatch behavior.
Trigger Lifecycle and Application Lifecycle
Triggers should normally be attached during application or automation initialization and detached when they are no longer required. A typical lifecycle is:EventTrigger and Automation
AnEventTrigger is a trigger mechanism. It does not itself define an automation workflow or persist automation state.
Its responsibility is intentionally small:
EventTrigger and AutomationWorker
EventTrigger and AutomationWorker solve different problems.
EventTrigger determines when application logic should run:
AutomationWorker determines how an automation definition is executed:
EventTrigger itself does not create a background worker.
If the target calls AutomationWorker.submit(), the application explicitly chooses background execution.
AutomationWorker Execution Model
In BindAI v0.1,AutomationWorker provides both synchronous and background execution.
Synchronous execution:
ThreadPoolExecutor.
Conceptually:
Background Event Handling
An event trigger can explicitly delegate work to anAutomationWorker:
EventTrigger and Workflows
An event trigger can be used as the entry point for application logic that invokes a workflow. For example:EventTrigger itself does not contain workflow-specific logic.
The same principle applies when a trigger invokes another BindAI executable.
EventTrigger and Agents
An event trigger can listen to an event bus associated with an execution context used by agent execution. For example:EventBus, not a hard-coded agent.events attribute.
Applications should pass the event bus that actually publishes the events they want to observe.
EventTrigger and Connections
An event trigger can also invoke application logic that uses a BindAI Connection. For example:Wildcard Events
The underlyingEventBus supports wildcard subscriptions through the "*" event name.
For example:
EventBus capability rather than special behavior implemented by EventTrigger.
EventTrigger subscribes using the event name supplied to its constructor:
EventBus semantics.
Handler Execution
When a matching event is received,EventTrigger checks whether it is enabled:
Synchronous Event Dispatch
The underlying BindAIEventBus dispatches subscribed handlers synchronously.
Conceptually:
EventTrigger itself does not create a background thread or process.
If the target calls AutomationWorker.submit(), background execution begins explicitly through the worker.
This distinction is important:
Trigger Registry
Trigger registration and lookup are separate from theEventTrigger implementation.
EventTrigger itself does not maintain a global registry.
If an application uses TriggerRegistry, the registry is responsible for managing trigger instances while EventTrigger remains responsible for subscribing to and unsubscribing from its event source.
For example:
Error Handling
EventTrigger does not wrap the target callable in its own retry or error-management mechanism.
The target is invoked directly:
EventBus isolates exceptions raised by event handlers and logs the failure rather than allowing one handler failure to prevent other subscribed handlers from being processed.
Applications should still handle expected failures at the appropriate application or automation layer.
For example:
EventTrigger automatically retries failed targets.
Security Considerations
Event payloads may contain application data. Targets should therefore treat incoming events as application input and validate or sanitize values when necessary. Recommended practices include:- validate event payloads before performing sensitive actions
- avoid exposing secrets through event payloads
- avoid logging credentials or tokens
- restrict which components can publish sensitive events
- keep event targets narrowly scoped
- use appropriate authorization before performing external actions
Testing Event Triggers
Event triggers can be tested using an isolatedEventBus.
Example:
- the trigger attaches correctly
- matching events invoke the target
- disabled triggers do not invoke the target
- detached triggers no longer receive events
- repeated
attach()does not duplicate subscriptions - repeated
detach()is safe - multiple triggers can receive the same event according to
EventBusbehavior
Current Implementation
The current event-trigger implementation provides:Triggerbase abstraction- trigger enable/disable state
attach()lifecycledetach()lifecycleEventTrigger- explicit
EventBusdependency - event-name subscription through
EventBus.subscribe() - callable event targets
- delivery of the original
Eventobject - duplicate-attachment protection
- safe repeated detachment
AutomationWorker for explicit synchronous or in-process background execution.
The trigger and worker remain separate abstractions.
Current Limitations
The currentEventTrigger implementation does not provide:
- persistent trigger state
- durable event delivery
- distributed event processing
- trigger-specific queues
- automatic retries
- dead-letter handling
- built-in scheduling
- built-in authentication
- built-in authorization
- distributed worker coordination
AutomationWorker also does not provide:
- distributed job queues
- cross-process worker coordination
- automatic failover
- worker autoscaling
- durable distributed execution
Architecture
The current relationship can be summarized as:Relationship to Observability
BindAI also provides structured events for runtime observability. AnEventRecorder can subscribe to an EventBus and retain events in memory for inspection.
This is separate from EventTrigger:
EventTrigger reacts to a configured event by invoking a target.
The same EventBus can therefore have multiple independent subscribers.
Current Scope
For BindAI v0.1, event triggers provide a simple foundation for event-driven automation. The recommended architecture is:AutomationWorker.
Future Direction
Future versions can build on this foundation to provide more advanced event-driven execution, including:- durable event processing
- queue-backed automation
- distributed workers
- retry policies
- dead-letter handling
- persistent trigger state
- richer event routing
- external event sources
- distributed scheduling
- production tracing and metrics
EventTrigger implementation and should not be assumed to be available in BindAI v0.1.
Summary
EventTrigger connects an existing EventBus to a callable target.
The basic lifecycle is:
AutomationWorker:
AutomationWorker provides the separate in-process execution capability when the application needs background automation.
More advanced durable and distributed automation capabilities remain separate roadmap work.